1
2
3
4
5
6
7 package net.sf.pmr.keopsframework.domain.collection;
8
9 import java.util.Collection;
10
11 import net.sf.pmr.keopsframework.data.DomainListMapper;
12 import net.sf.pmr.keopsframework.domain.LoadStatusEnum;
13
14 import org.apache.commons.logging.Log;
15 import org.apache.commons.logging.LogFactory;
16
17
18 /***
19 * @author Arnaud To change the template for this generated type comment go to
20 * Window>Preferences>Java>Code Generation>Code and Comments
21 */
22
23 public class GhostDomainCollectionImpl implements GhostDomainCollection {
24
25 /***
26 * Logger for this class
27 */
28 private static final Log LOGGER = LogFactory.getLog(GhostDomainCollectionImpl.class);
29
30 /***
31 * Status of the domain object
32 */
33 private LoadStatusEnum status = LoadStatusEnum.GHOST;
34
35 /***
36 * Collection
37 */
38 private Collection collection;
39
40 /***
41 * Loader to user for the list
42 */
43 private DomainListMapper mapper;
44
45 /***
46 * constructor made private
47 */
48 private GhostDomainCollectionImpl() {
49 }
50
51 /***
52 * constructor
53 *
54 * @param loader
55 * to user for the list
56 */
57 public GhostDomainCollectionImpl(final DomainListMapper mapper) {
58 this.mapper = mapper;
59 }
60
61 /***
62 * mark the object as loading
63 */
64 protected final void markLoading() {
65 status = LoadStatusEnum.LOADING;
66 }
67
68 /***
69 * mark the object as loaded: list and each object in the list
70 */
71 protected final void markLoaded() {
72
73 status = LoadStatusEnum.LOADED;
74 }
75
76 /***
77 * Is the object a ghost (ie no data have been loaded )
78 *
79 * @return boolean
80 */
81 protected final boolean isGhost() {
82 LOGGER.debug("isGhost() - start");
83
84 if (status.equals(LoadStatusEnum.GHOST)) {
85 LOGGER.debug("isGhost() - end - return value = " + true);
86 return true;
87 } else {
88 LOGGER.debug("isGhost() - end - return value = " + false);
89 return false;
90 }
91 }
92
93 /***
94 * @return loadStatus
95 */
96 public final LoadStatusEnum getStatus() {
97 return status;
98 }
99
100 /***
101 * @param enum
102 * enumeration of status
103 */
104 protected final void setStatus(final LoadStatusEnum enum) {
105 status = enum;
106 }
107
108 /***
109 * @return collection collection
110 */
111 public final Collection loadForObject(Object objectToLoadFor) {
112
113 if (isGhost()) {
114 markLoading();
115 collection = mapper.findCollectionForObject(objectToLoadFor);
116 markLoaded();
117 }
118
119 return collection;
120 }
121
122 /***
123 * @param collection The list to set.
124 */
125 public void setCollection(final Collection collection) {
126 this.collection = collection;
127
128 if (collection.size() > 0) markLoaded();
129 }
130 }